#include <iostream>

void arr_init();
void arr_index();
void arr_for1();
void arr_for2();
void chars();

int main(int argc, char *argv[]) {
  std::cout << "==== ch02 p02 ====" << std::endl;
  arr_init();
  arr_index();
  std::cout << "---- arr_for1() ----" << std::endl;
  arr_for1();
  std::cout << "---- arr_for2() ----" << std::endl;
  arr_for2();
  std::cout << "---- chars() ----" << std::endl;
  chars();
  return 0;
}

void arr_init() {
  int arr1[]{1, 2, 3, 4, 5}; // 初始化为 [1, 2, 3, 4, 5]
  int arr2[] = {2, 3, 4};    // 初始化为 [2, 3, 4]
  int arr3[5]{1, 2};         // 初始为 [1, 2, 0, 0, 0]
  int arr4[5]{};             // 初始为 [0, 0, 0, 0, 0]
}

void arr_index() {
  int arr[]{1, 2, 3, 4, 5};
  std::cout << arr[0] << std::endl; // 输出 1
  std::cout << arr[1] << std::endl; // 输出 2
}

void arr_for1() {
  int arr[]{1, 2, 3};
  auto size = sizeof(arr) / sizeof(arr[0]);
  for (size_t i = 0; i < size; i++) {
    std::cout << arr[i] << std::endl;
  }
}

void arr_for2() {
  int arr[]{1, 2, 3};
  for (auto elem : arr) {
    std::cout << elem << std::endl;
  }
}

void chars() {
  char s1[] = "Hello, ";
  const char *s2 = "world!";
  printf("%s%s\n", s1, s2); // 输出 "Hello, world!"
  const char *s3 = "Hello"
                   ", "
                   "world!";
  printf("%s\n", s3); // 输出 "Hello, world!"
}
